package com.itheima.springbootwebtlias.mapper;

import com.itheima.springbootwebtlias.pojo.ClaQueryParam;
import com.itheima.springbootwebtlias.pojo.Clazz;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ClazzMapper {

    @Select("select * from clazz")
    List<Clazz> selectAll();

    @Insert("insert into clazz(id, name, room, begin_date, end_date, master_id, subject,create_time,update_time) " +
            "values (null,#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void saveClazz(Clazz clazz);


    List<Clazz> selectByCondition(ClaQueryParam queryParam);

    // 根据id删除班级
    @Delete("delete from clazz where id = #{id}")
    void removeById(Integer id);

    // 根据id查询班级
    @Select("select * from clazz where id = #{id}")
    Clazz queryById(Integer id);

    //  更新班级
    void update(Clazz clazz);

    //  根据班级id查询班级人数
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer selectByClazzId(Integer id);
}
